<template>
  <div id="app">
    <!-- 头部 -->
    <ToBar :key="tobarKey" />
    <!-- 导航 -->
    <Header />
    <router-view @updateTobarKey="updateTobarFn" />
    <!-- 底部 -->
    <Footer />
    <!-- 登录框 -->
    <Login v-show="isShowLoginModal" />
    <!-- 提示框组件 -->
    <!-- vue提供了transition 过渡组件 -->
    <transition name="slide">
      <Toast v-show="isShowToast" />
    </transition>
  </div>
</template>
<script>
import ToBar from "./components/ToBar.vue";
import Header from "./components/Header.vue";
import Footer from "./components/Footer.vue";
import Login from "./components/Login.vue";
import Toast from "./components/Toast.vue";
import { mapState } from "vuex";
// import axios from "@/request/request";
import { Remen, UserProfilesAPI } from "@/request/api";

export default {
  data() {
    return {
      tobarKey: 0,
    };
  },
  components: {
    Footer,
    Header,
    ToBar,
    Login,
    Toast,
  },
  computed: {
    ...mapState({
      // 属性:state => state.模块名称.属性名
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        if (newVal != oldVal) {
          // key属性的值一变化，就会做组件重载，从而执行created函数
          // console.log("组件重载!", newVal, oldVal);
          this.tobarKey++;
        }
      },
    },
  },
  methods: {
    updateTobarFn() {
      // console.log('tobarKey更新了')
      this.tobarKey++;
    },
  },
  created() {
    // 获取配置文件        process.env..属性名
    console.log("配置为:", process.env.VUE_APP_BASE_URL);
    console.log("配置为:", process.env.VUE_APP_MY_TEXT);
  },
};
</script>
<style lang="less">
/* 可以设置不同的进入和离开动画 */
/* 设置持续时间和动画函数 */
.slid-enter-active {
  transition: all 0.3s ease;
}
.slide-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-enter, .slide-leave-to
/* .slide-fade-leave-active for below version 2.1.8 */ {
  transform: translateX(10px);
  opacity: 0;
}
</style>
